const express = require('express')
const app = express()
const {RouterControl} = require('./router/router')
const history = require('connect-history-api-fallback')

// 应对单页应用
app.use(history({
  verbose: true,
  index: '/'
}))

// 路由总控
RouterControl(app)

// 静态资源
app.use(express.static('public', {
  maxAge: 6000
}))

// 模板控制
app.set('views', './view')
app.set('view engine', 'ejs')

// 兜底错误处理
app.use((err, req, res, next) => {
  if (err) {
    console.log(err)
    res.status(500).send('something broke')
  }
})

app.listen(1111, () => {
  console.log('1111端口 -----  start')
})